![]() |
PATH![]() |
![]() ![]() |
Repeat statements are used to create loops, or groups of repeated statements, in scripts. There are several types of Repeat statements, each differing in the way it terminates the loop. For example, you can loop a specific number of times, loop for each item in a list, loop while a specified condition is true, or loop until a condition is true. More elaborate forms of the Repeat statement use a loop variable, which you can refer to in the body of the loop, to control the number of iterations.
For information on testing and debugging Repeat statements, see the example in Repeat With (loopVariable) In (list).
Each available type of Repeat statement is described in one of the following sections:
There may often be no clear advantage in picking one form of Repeat loop over another, so it is a good idea to pick a form that you think will make the most sense to someone reading the script. In some cases, a Filter reference form may be more appropriate than a Repeat statement. For example, the following script closes every AppleWorks window that isn't named "Old Report (WP)".
tell application "AppleWorks"
close every window whose name is not "Old Report (WP)"
end tell
You could certainly count the open windows and set up a Repeat loop that checks the name of each window and closes the window if it isn't named "Old Report (WP)". In this case, however, the Filter form does most of the work for you. For more information on filters, see Filter and Using the Filter Reference Form.